{extend name="$adminPage"}

{block name="headStyle"}
<style type="text/css">

</style>
{/block}

{block name="content"}
<form type="yunj" id="{$builderId}"></form>
<script type="text/javascript">
    layui.use(["jquery", 'yunj'], function () {
        let win = window;
        let doc = document;
        let $ = layui.jquery;

        // 处理类型相关字段的显示隐藏
        function handleTypeFieldShowHide(form) {
            let typeObj = form.getFieldObj('type');
            let iconObj = form.getFieldObj('icon');
            let pageOpenObj = form.getFieldObj('page_open');
            if (['11', '22'].indexOf(typeObj.getValue()) !== -1) {
                iconObj.boxEl.show();
                pageOpenObj.boxEl.show();
            } else {
                iconObj.boxEl.hide();
                pageOpenObj.boxEl.hide();
            }
        }

        // 处理请求类型相关字段的显示隐藏
        function handleRequestTypeFieldShowHide(form) {
            let requestTypeObj = form.getFieldObj('request_type');
            let requestIdObj = form.getFieldObj('request_id');
            let requestUrlObj = form.getFieldObj('request_url');
            if (requestTypeObj.getValue() === '11'){
                requestIdObj.boxEl.show();
                requestUrlObj.boxEl.hide();
            }else{
                requestIdObj.boxEl.hide();
                requestUrlObj.boxEl.show();
            }
        }

        // 绑定渲染完成后的事件
        $(doc).bind(`yunj_form_{$builderId}_render_done`, function (e, form) {
            handleTypeFieldShowHide(form);
            handleRequestTypeFieldShowHide(form);
        });

        // 绑定类型切换事件
        $(doc).bind(`yunj_form_{$builderId}_type_change`, function (e, field) {
            let form = yunj.formObj(field.formId);
            handleTypeFieldShowHide(form);
        });
        $(doc).bind(`yunj_form_{$builderId}_request_type_change`, function (e, field) {
            let form = yunj.formObj(field.formId);
            handleRequestTypeFieldShowHide(form);
        });
    });
</script>
{/block}